#include "RTC.h"
#include "uart_cmd.h"
#include "driver/uart.h"

char* Decber_main = "main.n1.val=12\xff\xff\xff";
char* Decber_sign = "sign.n3.val=12\xff\xff\xff";
char* Decber_log_1 = "log.n0.val=12\xff\xff\xff";
char* Decber_log_2 = "log.n5.val=12\xff\xff\xff";
char* Decber_log_3 = "log.n10.val=12\xff\xff\xff";
char* Decber_log_4 = "log.n15val=12\xff\xff\xff";

char* send_year_main = "year.val=";
char* send_month_main = "main.n1.val=";
char* send_day_main = "main.n2.val=";
char* send_hour_main = "main.n3.val=";
char* send_min_main = "main.n4.val=";
char* send_sec_main = "main.n5.val=";
char* send_week_main = "main.t8.txt=\"";
char* send_str_tail = "\"\xff\xff\xff";

char* send_month_log_1 = "log.n0.val=";
char* send_day_log_1 = "log.n1.val=";
char* send_hour_log_1 = "log.n2.val=";
char* send_min_log_1 = "log.n3.val=";
char* send_sec_log_1 = "log.n4.val=";

char* send_month_log_2 = "log.n5.val=";
char* send_day_log_2 = "log.n6.val=";
char* send_hour_log_2 = "log.n7.val=";
char* send_min_log_2 = "log.n8.val=";
char* send_sec_log_2 = "log.n9.val=";

char* send_month_log_3 = "log.n10.val=";
char* send_day_log_3 = "log.n11.val=";
char* send_hour_log_3 = "log.n12.val=";
char* send_min_log_3 = "log.n13.val=";
char* send_sec_log_3 = "log.n14.val=";

char* send_month_log_4 = "log.n15.val=";
char* send_day_log_4 = "log.n16.val=";
char* send_hour_log_4 = "log.n17.val=";
char* send_min_log_4 = "log.n18.val=";
char* send_sec_log_4 = "log.n19.val=";


uint8_t week1[] = {0xD2,0xBB};
uint8_t week2[] = {0xB6,0xFE};
uint8_t week3[] = {0xC8,0xFD};
uint8_t week4[] = {0xCB,0xC4};
uint8_t week5[] = {0xCE,0xE5};
uint8_t week6[] = {0xC1,0xF9};
uint8_t week7[] = {0xC8,0xD5};

char* send_hour_sign = "sign.n0.val=";
char* send_min_sign = "sign.n1.val=";
char* send_sec_sign = "sign.n2.val=";
char* send_month_sign = "sign.n3.val=";
char* send_day_sign = "sign.n4.val=";
char* send_tail = "\xff\xff\xff";

void RTC_time_init()
{
    struct tm timeinfo;
    timeinfo.tm_year = 2024 - 1900;  // 设置年份
    timeinfo.tm_mon = 12;  // 设置月份
    timeinfo.tm_mday = 1;  // 设置日期
    timeinfo.tm_hour = 13;  // 设置小时
    timeinfo.tm_min = 45;  // 设置分钟
    timeinfo.tm_sec = 30;  // 设置秒
    setenv("TZ", "CST-8", 1);  // 设置时区为中国标准时间
    tzset();  // 使时区设置生效

    const time_t now = mktime(&timeinfo);  // 将tm结构体转换为time_t格式
    struct timeval tv = { .tv_sec = now };  // 定义一个timeval结构体变量tv，并设置其秒数
    settimeofday(&tv, NULL);  // 设置系统时间
}

void RTC_Sendtime_sign(time_t* now_get,struct tm* timeinfo_get_param)
{
    time(now_get);  // 获取当前时间
    localtime_r(now_get, timeinfo_get_param);  // 将time_t格式的时间转换为tm结构体格式
    uint8_t time[2] = {'0','0'};
    //hour
    time[0] = '0' + timeinfo_get_param->tm_hour / 10;
    time[1] = '0' + timeinfo_get_param->tm_hour % 10;
    uart_write_bytes(SCREEN_UART,send_hour_sign,strlen(send_hour_sign));
    uart_write_bytes(SCREEN_UART,time,2);
    uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
    //min
    time[0] = '0' + timeinfo_get_param->tm_min / 10;
    time[1] = '0' + timeinfo_get_param->tm_min % 10;
    uart_write_bytes(SCREEN_UART,send_min_sign,strlen(send_min_sign));
    uart_write_bytes(SCREEN_UART,time,2);
    uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
    
    //sec
    time[0] = '0' + timeinfo_get_param->tm_sec / 10;
    time[1] = '0' + timeinfo_get_param->tm_sec % 10;
    uart_write_bytes(SCREEN_UART,send_sec_sign,strlen(send_sec_sign));
    uart_write_bytes(SCREEN_UART,time,2);
    uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
    //month
    if(timeinfo_get_param->tm_mon < 12 && timeinfo_get_param->tm_mon > 0)
    {
        time[0] = '0' + timeinfo_get_param->tm_mon / 10;
        time[1] = '0' + timeinfo_get_param->tm_mon % 10;
        uart_write_bytes(SCREEN_UART,send_month_sign,strlen(send_month_sign));
        uart_write_bytes(SCREEN_UART,time,2);
        uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
    }
    else if(timeinfo_get_param->tm_mon == 0)
    {
        uart_write_bytes(SCREEN_UART,Decber_sign,strlen(Decber_sign));
    }
    //date
    time[0] = '0' + timeinfo_get_param->tm_mday / 10;
    time[1] = '0' + timeinfo_get_param->tm_mday % 10;
    uart_write_bytes(SCREEN_UART,send_day_sign,strlen(send_day_sign));
    uart_write_bytes(SCREEN_UART,time,2);
    uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));

}

void Show_card_clock(Card_clock_t* set_time)
{
    uint8_t element = (set_time->month[0] - '0') * 10 + (set_time->month[1] - '0');
    if(element > 0 && element < 12)
    {
    //month
    uart_write_bytes(SCREEN_UART,send_month_log_1,strlen(send_month_log_1));
    uart_write_bytes(SCREEN_UART,set_time->month,2);
    uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
    }
    else
    {
        uart_write_bytes(SCREEN_UART,Decber_log_1,strlen(Decber_log_1));
    }
    //date
    uart_write_bytes(SCREEN_UART,send_day_log_1,strlen(send_day_log_1));
    uart_write_bytes(SCREEN_UART,set_time->date,2);
    uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
    //hour
    uart_write_bytes(SCREEN_UART,send_hour_log_1,strlen(send_hour_log_1));
    uart_write_bytes(SCREEN_UART,set_time->hour,2);
    uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
    //min
    uart_write_bytes(SCREEN_UART,send_min_log_1,strlen(send_min_log_1));
    uart_write_bytes(SCREEN_UART,set_time->min,2);
    uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
    //sec
    uart_write_bytes(SCREEN_UART,send_sec_log_1,strlen(send_sec_log_1));
    uart_write_bytes(SCREEN_UART,set_time->sec,2);
    uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
}

void RTC_Sendtime_main(time_t* now_get,struct tm* timeinfo_get_param)
{
    time(now_get);  // 获取当前时间
    localtime_r(now_get, timeinfo_get_param);  // 将time_t格式的时间转换为tm结构体格式
    char time[2] = {'0','0'};
    //year
    int year_last_two_digits = (timeinfo_get_param->tm_year - 1900) % 100;
    time[0] = '0' + year_last_two_digits / 10;
    time[1] = '0' + year_last_two_digits % 10;
    uart_write_bytes(SCREEN_UART,send_year_main,strlen(send_year_main));
    uart_write_bytes(SCREEN_UART,time,2);
    uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
    //month
    if(timeinfo_get_param->tm_mon < 12 && timeinfo_get_param->tm_mon > 0)
    {
        time[0] = '0' + timeinfo_get_param->tm_mon / 10;
        time[1] = '0' + timeinfo_get_param->tm_mon % 10;
        uart_write_bytes(SCREEN_UART,send_month_main,strlen(send_month_main));
        uart_write_bytes(SCREEN_UART,time,2);
        uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
    }
    else if(timeinfo_get_param->tm_mon == 0)
    {
        uart_write_bytes(SCREEN_UART,Decber_main,strlen(Decber_main));
    }
    //date
    time[0] = '0' + timeinfo_get_param->tm_mday / 10;
    time[1] = '0' + timeinfo_get_param->tm_mday % 10;
    uart_write_bytes(SCREEN_UART,send_day_main,strlen(send_day_main));
    uart_write_bytes(SCREEN_UART,time,2);
    uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
    //hour
    time[0] = '0' + timeinfo_get_param->tm_hour / 10;
    time[1] = '0' + timeinfo_get_param->tm_hour % 10;
    uart_write_bytes(SCREEN_UART,send_hour_main,strlen(send_hour_main));
    uart_write_bytes(SCREEN_UART,time,2);
    uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
    //min
    time[0] = '0' + timeinfo_get_param->tm_min / 10;
    time[1] = '0' + timeinfo_get_param->tm_min % 10;
    uart_write_bytes(SCREEN_UART,send_min_main,strlen(send_min_main));
    uart_write_bytes(SCREEN_UART,time,2);
    uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
    //sec
    time[0] = '0' + timeinfo_get_param->tm_sec / 10;
    time[1] = '0' + timeinfo_get_param->tm_sec % 10;
    uart_write_bytes(SCREEN_UART,send_sec_main,strlen(send_sec_main));
    uart_write_bytes(SCREEN_UART,time,2);
    uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
    if(timeinfo_get_param->tm_mon == 0)
    {
        if(timeinfo_get_param->tm_wday >= 4)
        {
            timeinfo_get_param->tm_wday = timeinfo_get_param->tm_wday - 3;
        }
        else
        {
            timeinfo_get_param->tm_wday = 7 + timeinfo_get_param->tm_wday - 3;
        }
    }
    else
    {
        if(timeinfo_get_param->tm_wday >= 3)
        {
            timeinfo_get_param->tm_wday = timeinfo_get_param->tm_wday - 3;
        }
        else
        {
            timeinfo_get_param->tm_wday = 7 + timeinfo_get_param->tm_wday - 3;
        }
    }
    
    if(timeinfo_get_param->tm_wday == 7)
    {
        uart_write_bytes(SCREEN_UART,send_week_main,strlen(send_week_main));
        uart_write_bytes(SCREEN_UART,week7,2);
        uart_write_bytes(SCREEN_UART,send_str_tail,strlen(send_str_tail));
    }
    else if(timeinfo_get_param->tm_wday == 1)
    {
        uart_write_bytes(SCREEN_UART,send_week_main,strlen(send_week_main));
        uart_write_bytes(SCREEN_UART,week1,2);
        uart_write_bytes(SCREEN_UART,send_str_tail,strlen(send_str_tail));
    }
    else if(timeinfo_get_param->tm_wday == 2)
    {
        uart_write_bytes(SCREEN_UART,send_week_main,strlen(send_week_main));
        uart_write_bytes(SCREEN_UART,week2,2);
        uart_write_bytes(SCREEN_UART,send_str_tail,strlen(send_str_tail));
    }else if(timeinfo_get_param->tm_wday == 3)
    {
        uart_write_bytes(SCREEN_UART,send_week_main,strlen(send_week_main));
        uart_write_bytes(SCREEN_UART,week3,2);
        uart_write_bytes(SCREEN_UART,send_str_tail,strlen(send_str_tail));
    }else if(timeinfo_get_param->tm_wday == 4)
    {
        uart_write_bytes(SCREEN_UART,send_week_main,strlen(send_week_main));
        uart_write_bytes(SCREEN_UART,week4,2);
        uart_write_bytes(SCREEN_UART,send_str_tail,strlen(send_str_tail));
    }else if(timeinfo_get_param->tm_wday == 5)
    {
        uart_write_bytes(SCREEN_UART,send_week_main,strlen(send_week_main));
        uart_write_bytes(SCREEN_UART,week5,2);
        uart_write_bytes(SCREEN_UART,send_str_tail,strlen(send_str_tail));
    }else if(timeinfo_get_param->tm_wday == 6)
    {
        uart_write_bytes(SCREEN_UART,send_week_main,strlen(send_week_main));
        uart_write_bytes(SCREEN_UART,week6,2);
        uart_write_bytes(SCREEN_UART,send_str_tail,strlen(send_str_tail));
    }
}


void Show_Personal_Log(time_t* card_time,uint8_t page_num)
{
    struct tm mem_size = {0};
    struct tm* timeinfo_get_param = &mem_size;
    char time[2] = {'0','0'};


        if(card_time[page_num * 3] == 0)
        {
            //month
            uart_write_bytes(SCREEN_UART,send_month_log_1,strlen(send_month_log_1));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //date
            uart_write_bytes(SCREEN_UART,send_day_log_1,strlen(send_day_log_1));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //hour
            uart_write_bytes(SCREEN_UART,send_hour_log_1,strlen(send_hour_log_1));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //min
            uart_write_bytes(SCREEN_UART,send_min_log_1,strlen(send_min_log_1));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //sec
            uart_write_bytes(SCREEN_UART,send_sec_log_1,strlen(send_sec_log_1));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
        }
        else 
        //第一行
        {
            localtime_r(&(card_time[page_num * 3]),timeinfo_get_param);  // 将time_t格式的时间转换为tm结构体格式
            if(timeinfo_get_param->tm_mon < 12 && timeinfo_get_param->tm_mon > 0)
            {
                time[0] = '0' + timeinfo_get_param->tm_mon / 10;
                time[1] = '0' + timeinfo_get_param->tm_mon % 10;
                uart_write_bytes(SCREEN_UART,send_month_log_1,strlen(send_month_log_1));
                uart_write_bytes(SCREEN_UART,time,2);
                uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            }
            else if(timeinfo_get_param->tm_mon == 0)
            {
                uart_write_bytes(SCREEN_UART,Decber_log_1,strlen(Decber_log_1));
            }
            //date
            time[0] = '0' + timeinfo_get_param->tm_mday / 10;
            time[1] = '0' + timeinfo_get_param->tm_mday % 10;
            uart_write_bytes(SCREEN_UART,send_day_log_1,strlen(send_day_log_1));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //hour
            time[0] = '0' + timeinfo_get_param->tm_hour / 10;
            time[1] = '0' + timeinfo_get_param->tm_hour % 10;
            uart_write_bytes(SCREEN_UART,send_hour_log_1,strlen(send_hour_log_1));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //min
            time[0] = '0' + timeinfo_get_param->tm_min / 10;
            time[1] = '0' + timeinfo_get_param->tm_min % 10;
            uart_write_bytes(SCREEN_UART,send_min_log_1,strlen(send_min_log_1));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //sec
            time[0] = '0' + timeinfo_get_param->tm_sec / 10;
            time[1] = '0' + timeinfo_get_param->tm_sec % 10;
            uart_write_bytes(SCREEN_UART,send_sec_log_1,strlen(send_sec_log_1));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
        }

        time[0] = '0';
        time[1] = '0';
        if(card_time[page_num * 3 + 1] == 0)
        {
            //month
            uart_write_bytes(SCREEN_UART,send_month_log_2,strlen(send_month_log_2));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //date
            uart_write_bytes(SCREEN_UART,send_day_log_2,strlen(send_day_log_2));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //hour
            uart_write_bytes(SCREEN_UART,send_hour_log_2,strlen(send_hour_log_2));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //min
            uart_write_bytes(SCREEN_UART,send_min_log_2,strlen(send_min_log_2));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //sec
            uart_write_bytes(SCREEN_UART,send_sec_log_2,strlen(send_sec_log_2));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
        }
        else
        {
            //第二行
            localtime_r(&(card_time[page_num * 3 + 1]),timeinfo_get_param);  // 将time_t格式的时间转换为tm结构体格式
            if(timeinfo_get_param->tm_mon < 12 && timeinfo_get_param->tm_mon > 0)
            {
                time[0] = '0' + timeinfo_get_param->tm_mon / 10;
                time[1] = '0' + timeinfo_get_param->tm_mon % 10;
                uart_write_bytes(SCREEN_UART,send_month_log_2,strlen(send_month_log_2));
                uart_write_bytes(SCREEN_UART,time,2);
                uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            }
            else if(timeinfo_get_param->tm_mon == 0)
            {
                uart_write_bytes(SCREEN_UART,Decber_log_2,strlen(Decber_log_2));
            }
            //date
            time[0] = '0' + timeinfo_get_param->tm_mday / 10;
            time[1] = '0' + timeinfo_get_param->tm_mday % 10;
            uart_write_bytes(SCREEN_UART,send_day_log_2,strlen(send_day_log_2));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //hour
            time[0] = '0' + timeinfo_get_param->tm_hour / 10;
            time[1] = '0' + timeinfo_get_param->tm_hour % 10;
            uart_write_bytes(SCREEN_UART,send_hour_log_2,strlen(send_hour_log_2));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //min
            time[0] = '0' + timeinfo_get_param->tm_min / 10;
            time[1] = '0' + timeinfo_get_param->tm_min % 10;
            uart_write_bytes(SCREEN_UART,send_min_log_2,strlen(send_min_log_2));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //sec
            time[0] = '0' + timeinfo_get_param->tm_sec / 10;
            time[1] = '0' + timeinfo_get_param->tm_sec % 10;
            uart_write_bytes(SCREEN_UART,send_sec_log_2,strlen(send_sec_log_2));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
        }

        time[0] = '0';
        time[1] = '0';
        if(card_time[page_num * 3 + 2] == 0)
        {
            //month
            uart_write_bytes(SCREEN_UART,send_month_log_3,strlen(send_month_log_3));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //date
            uart_write_bytes(SCREEN_UART,send_day_log_3,strlen(send_day_log_3));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //hour
            uart_write_bytes(SCREEN_UART,send_hour_log_3,strlen(send_hour_log_3));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //min
            uart_write_bytes(SCREEN_UART,send_min_log_3,strlen(send_min_log_3));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //sec
            uart_write_bytes(SCREEN_UART,send_sec_log_3,strlen(send_sec_log_3));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
        }
        else
        {
            //第三行
            localtime_r(&(card_time[page_num * 3 + 2]),timeinfo_get_param);  // 将time_t格式的时间转换为tm结构体格式
            if(timeinfo_get_param->tm_mon < 12 && timeinfo_get_param->tm_mon > 0)
            {
                time[0] = '0' + timeinfo_get_param->tm_mon / 10;
                time[1] = '0' + timeinfo_get_param->tm_mon % 10;
                uart_write_bytes(SCREEN_UART,send_month_log_3,strlen(send_month_log_3));
                uart_write_bytes(SCREEN_UART,time,2);
                uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            }
            else if(timeinfo_get_param->tm_mon == 0)
            {
                uart_write_bytes(SCREEN_UART,Decber_log_3,strlen(Decber_log_3));
            }
            //date
            time[0] = '0' + timeinfo_get_param->tm_mday / 10;
            time[1] = '0' + timeinfo_get_param->tm_mday % 10;
            uart_write_bytes(SCREEN_UART,send_day_log_3,strlen(send_day_log_3));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //hour
            time[0] = '0' + timeinfo_get_param->tm_hour / 10;
            time[1] = '0' + timeinfo_get_param->tm_hour % 10;
            uart_write_bytes(SCREEN_UART,send_hour_log_3,strlen(send_hour_log_3));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //min
            time[0] = '0' + timeinfo_get_param->tm_min / 10;
            time[1] = '0' + timeinfo_get_param->tm_min % 10;
            uart_write_bytes(SCREEN_UART,send_min_log_3,strlen(send_min_log_3));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
            //sec
            time[0] = '0' + timeinfo_get_param->tm_sec / 10;
            time[1] = '0' + timeinfo_get_param->tm_sec % 10;
            uart_write_bytes(SCREEN_UART,send_sec_log_3,strlen(send_sec_log_3));
            uart_write_bytes(SCREEN_UART,time,2);
            uart_write_bytes(SCREEN_UART,send_tail,strlen(send_tail));
        }

}